package vno.ky.aswing
{
	import fl.controls.ColorPicker;
	import fl.events.ListEvent;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import flashx.textLayout.events.SelectionEvent;
	
	import mx.events.ItemClickEvent;
	
	import org.aswing.ASColor;
	import org.aswing.AsWingManager;
	import org.aswing.BorderLayout;
	import org.aswing.FlowLayout;
	import org.aswing.Icon;
	import org.aswing.JButton;
	import org.aswing.JFrame;
	import org.aswing.JList;
	import org.aswing.JScrollPane;
	import org.aswing.JTabbedPane;
	import org.aswing.JWindow;
	import org.aswing.LoadIcon;
	import org.aswing.VectorListModel;
	import org.aswing.colorchooser.ColorRectIcon;
	import org.aswing.event.AWEvent;
	import org.aswing.event.ListItemEvent;
	
	public class MyList extends Sprite
	{
		private var list:Array=new Array();
		private var count:int=0;
		private var window:JWindow;
		private var tab:JTabbedPane=new JTabbedPane();					//分类标签
		private var resourse:Object;									//输入
		public function MyList(res:Object)
		{
			super();
			window=new JWindow(this);									//必须要加this 同frame
			window.getContentPane().setLayout(new FlowLayout());		//默认为LorderLayout，但是会忽略期望大小，不可设置高度和宽度。因而采用FlowLayout
			resourse=res;
			deal();
			var a:JList=new JList();
			a.clearSelection(true);
		}
		private function deal():void
		{
			for(var j:String in resourse)
			{
				list[count]=new JList(resourse[j]);
				tab.appendTab(new JScrollPane(list[count]),j);
				list[count].addEventListener(ItemClickEvent.ITEM_CLICK,ListenerA);
				
				list[count].setVisibleCellWidth(128);			//默认宽度200，高度6，高度设成其他值(过高)可能会导致滚动条显示不出来
				list[count].setVisibleRowCount(12);
				count++;
			}
			tab.setTabPlacement(JTabbedPane.RIGHT);
			addChild(tab);
			window.getContentPane().append(tab);							//frame直接.append时组件必须有名字，否则要通过此语句append
			window.pack();
			//window.setSizeWH(300, 200);									//不设定window的具体大小，则自动根据其内组件大小确定
			addChild(window);
			this.graphics.beginFill(0xFFFFFF);	//填充背景颜色
			this.graphics.drawRoundRect(1,1,window.getWidth(),window.getHeight(), 10);	//画矩形
			this.graphics.endFill();
			window.show();
			this.alpha = 0.6;
			this.addEventListener(MouseEvent.ROLL_OVER, showOn);
			this.addEventListener(MouseEvent.ROLL_OUT, showOff);
		}
		
		protected function showOn(event:MouseEvent):void
		{
			this.alpha = 1;
		}
		protected function showOff(event:MouseEvent):void
		{
			this.alpha = 0.6;
		}
		public function setWidth(width:int):void 						//设置list宽度
		{
			for(var i:int=0;i<count;i++)
			{
				list[i].setVisibleCellWidth(width);
			}
		}
		public function setHeight(height:int):void 						//设置list高度
		{
			for(var i:int=0;i<count;i++)
			{
				list[i].setVisibleRowCount(height);
			}
		}
		public function ListenerA(e:ListItemEvent):void
		{
			dispatchEvent(e);
			for(var i:int=0;i<count;i++)							//取消选中
			{
				list[i].clearSelection(true);
			}
		}
		override public function get width():Number
		{
			return window.width;
		}		
		override public function get height():Number
		{
			return window.height;
		}
	}
}